﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NHibernate.Linq;

namespace Perpus
{
    public class Perpus_Fungsi
    {
        NhibernateHelper help = new NhibernateHelper();

        public void TambahPegawai(string nama, string user, string pass)
        {    

            var factory =  help.CreateSessionFactory();

            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var employee = new Pegawai
                    {
                        nama_pegawai = nama,
                        username = user,
                        password = pass
                    };

                    session.Save(employee);
                    transaction.Commit();
                }
            }
        }

        public void TambahBuku(string nama, string stat, int dendax, int publish, int cat, int karang)
        {
            var factory = help.CreateSessionFactory();

            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var book = new Buku
                    {
                        //id_penerbit =  session.Load<Penerbit>(idpenerbit),
                        nama_buku = nama,
                        status = stat,
                        denda = dendax,
                        id_penerbit = session.Get<Penerbit>(publish),
                        id_kategori = session.Get<Kategori>(cat),
                        id_pengarang = session.Get<Pengarang>(karang)// Load<Penerbit>(idpenerbit)
                    };

                    session.Save(book);
                    transaction.Commit();

                }
            }
        }
    }
}
